<?php

namespace JsonLowCode\Form\Fields;

use JsonLowCode\UI\IconSelect;
use JsonLowCode\Form\Abstract\FieldAbstract;
use JsonLowCode\Form\Traits\HasClearable;
use JsonLowCode\Form\Traits\HasDisabled;
use JsonLowCode\Form\Traits\HasSize;

/**
 * @property IconSelect $element
 */
class IconSelectField extends FieldAbstract
{

    use HasDisabled, HasSize, HasClearable;

    protected array $icons = [
        'mdi:home','mdi:user','mdi:shop'
    ];

    protected function booting(): void
    {
        $this->element = new IconSelect();
        $this->element->inputStyle(['width'=>'200px']);
//        $json = file_get_contents(__DIR__."/../../../resources/assets/icon/bi.json");
        $json = $this->icons;
        $this->icons($json);

//        $this->icons(collect(json_decode($json,true))->map(function ($icon){
//            return $icon['name'];
//        })->random(54)->toArray());
    }

    protected function booted()
    {
        $this->defaultValue("");
    }

    /**
     * 未选中图标
     * @param string $emptyIcon
     * @param bool $isJSExpression
     * @return $this
     */
    public function emptyIcon(string $emptyIcon,  bool $isJSExpression = false): static
    {
        $this->element->emptyIcon($emptyIcon,$isJSExpression);
        return $this;
    }


    /**
     * 图标列表
     * @param string|array<int,string> $icons
     * @param bool $isJSExpression
     * @return $this
     */
    public function icons(string|array $icons = [],  bool $isJSExpression = false): static
    {
        $this->element->icons($icons, $isJSExpression);
        return $this;
    }
}
